package com.zhentao.controller;

import com.zhentao.dtos.Result;
import com.zhentao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("getVerificationCode")
    public Result getVerificationCode( String userMobile ) {
        try {
            Integer code = userService.getVerificationCode( userMobile );
            return Result.success( code );
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error();
    }

    @RequestMapping("register")
    public Result register( String phoneNumber, String password, String verificationCode ) {
        try {
            return userService.register( phoneNumber, password, verificationCode );
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error();
    }

    @RequestMapping("login")
    public Result login( String phoneNumber, String password ) {
        try {
            return userService.login( phoneNumber, password );
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error();
    }


}
